<?php 
	
?>
<?php
	include("include1.php");
	//ini_set('default_charset','utf-8');
	header("Content-type: application/json; charset=utf-8");
	$HMid = mysql_real_escape_string($_REQUEST["filter"]["filters"][0]["value"]);
	$verb = $_SERVER["REQUEST_METHOD"];
	//echo $verb;
	if(isset($_POST['models']))
	{
		$rs = mysql_query("DELETE FROM khoiluongmoithau WHERE id = '" . $_POST['models'][0]['CVid'] ."'");
		if ($rs) {
			echo json_encode($rs);
		}
		else {
			header("HTTP/1.1 500 Internal Server Error");
			echo "Failed on delete: " . $_POST['models'][0]['Column1'];
		}
	}
	if($verb == "GET")
	{
		if(isset($_REQUEST["xoa"]))
		{
			echo $_REQUEST["xoa"];
			$sql = "delete from danhsachcongtrinh where id='" . $_REQUEST["xoa"] . "'";echo $sql;
			$rs = mysql_query($sql);
			
		}
		else
		{
			header("Content-type: application/json; charset=utf-8");
			$arr = array();
			$sql = sprintf("select `id` as `CVid`, `MaCV`, `TenCV`, `DVT`, `KhoiLuong` from `khoiluongmoithau` where MaHM = '%s'", $HMid);
			$rs = mysql_query($sql);
			$temp="";
			while($obj = mysql_fetch_object($rs))
			{
					$arr[] = $obj;					
			}
			echo "{\"data\":" . json_encode($arr , JSON_UNESCAPED_UNICODE) . "}";
		}
	}
	
	if($verb == "POST")
	{
		$CVid = mysql_real_escape_string($_POST["CVid"]);
		$MaCV = mysql_real_escape_string($_POST["MaCV"]);
		$TenCV = mysql_real_escape_string($_POST["TenCV"]);
		$DVT = mysql_real_escape_string($_POST["DVT"]);
		$KhoiLuong = mysql_real_escape_string($_POST["KhoiLuong"]);
		
		
		$sql = sprintf("update khoiluongmoithau set MaCV = '%s', TenCV = '%s', KhoiLuong = '%s', DVT = '%s' where id = '%s'", $MaCV, $TenCV, $KhoiLuong, $DVT, $CVid);
		$rs = mysql_query($sql);
		
		if ($rs) {
        echo json_encode($rs);
		}
		else {
			header("HTTP/1.1 500 Internal Server Error");
			echo "Không thể cập nhật công trình: " .$TenCT;
		}
		
		
		
		}
	
	
?>